﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BacteriaSimulation.Simulation
{
    class CyanobacteriumSimulationStrategy : BacteriumSimulationStrategy
    {
        protected Vector2D NewSpeed = null;

        public override void PerformSimulationStep(Bacterium bacterium)
        {
            Double maxEnergyIncrement = Math.Min(bacterium.EnergyIncrement, bacterium.MaxEnergy - bacterium.Energy);
            if (bacterium.Energy > bacterium.MaxEnergy)
            {
                bacterium.Energy = bacterium.MaxEnergy;
            }
            else
            {
                bacterium.Grow(maxEnergyIncrement);
            }

            if (NewSpeed != null)
            {
                bacterium.Speed = NewSpeed;
                NewSpeed = null;
            }
        }

        public override void WallCollisionDetected(Bacterium bacterium, WALL_COLLISION_TYPE collisionType)
        {
            switch (collisionType)
            {
                case WALL_COLLISION_TYPE.BOTTOM:
                    {
                        bacterium.Speed.YComponent *= -1;
                        break;
                    }
                case WALL_COLLISION_TYPE.RIGHT:
                    {
                        bacterium.Speed.XComponent *= -1;
                        break;
                    }
                case WALL_COLLISION_TYPE.TOP:
                    {
                        bacterium.Speed.YComponent *= -1;
                        break;
                    }
                case WALL_COLLISION_TYPE.LEFT:
                    {
                        bacterium.Speed.XComponent *= -1;
                        break;
                    }
            }
        }

        public override void BacteriumCollisionDetected(Bacterium bacterium, Bacterium collidedBacterium)
        {
            //System.Console.WriteLine(this.ToString() + ": collision detected");
            //NewSpeed = collidedBacterium.Speed.Clone();
            //bacterium.Speed.XComponent *= -1;
            //bacterium.Speed.YComponent *= -1;
        }
    }
}
